#include <bits/stdc++.h>

using namespace std;
#define gc() (ibo_ == ied_ ? (ied_ = buf + fread(ibo_ = buf, 1, 1 << 20, stdin), ibo_ == ied_ ? EOF : *ibo_++) : *ibo_++)
#define read() ({ int x = 0, f = 1; char c = gc(); while(c < '0' || c > '9') { if (c == '-') f = -1; c = gc();} while(c >= '0' && c <= '9') x = x * 10 + (c & 15), c = gc(); f * x; })
char buf[1 << 20], puf[1 << 20], *_p_ = puf, *ibo_, *ied_;
#define pr(x) (_p_ - puf == 1 << 20 ? (fwrite(puf, 1, 1 << 20, stdout), _p_ = puf) : 0, *_p_++ = x)
int print(int x) { return x <= 9 ? pr(x + '0') : (print(x / 10), pr(x % 10 + '0')); }
const int N = 1e6 + 5;
typedef long long LL;

unordered_map<LL, int> M;
int M2[N], k;
int fa[N];
int find(int x) {
    return fa[x] != x ? fa[x] = find(fa[x]) : x;
}
LL numset(int x, int y) {
    return x * 10000000000ll + y;
}
signed main() {
    int n;
    n = read();
    while (n --) {
        int op, x, y;
        op = read(), x = read(), y = read();
        if (op & 1) {
            LL c = numset(x, y);
            M[c] = ++ k;
            M2[k] = 6;
            fa[k] = k;
            int dx[6] = {1, 0, 0, -1, 1, -1}, dy[6] = {0, 1, -1, 0, -1, 1}, res = 0;//左上右下
            for (int i = 0; i < 6; ++ i) {
                int X = x + dx[i], Y = y + dy[i];
                int a = M[numset(X, Y)];
                if (!a) continue;
                int b = find(a);
                if (b != k) {
                    fa[b] = k;
                    M2[k] += M2[b] - 2;
                } else {
                    M2[k] -= 2;
                }
            }
        } else {
            print(M2[find(M[numset(x, y)])]);  pr('\n');
        }
    }
    fwrite(puf, 1, _p_ - puf, stdout);
    return 0;
}
